<template>
  <div class="navbar">
    <div class="breadcrumb-container">
      <router-link class="nav_item" to="/">管理后台</router-link>
      <router-link class="nav_item" to="/">返回前台</router-link>
      <router-link v-if="shopInfo.houtai != 0" class="nav_item" :class="$route.path == '/shop/set' ? 'active' : ''" to="/shop/set">店铺后台</router-link>
      <router-link v-if="shopInfo.houtai != 0" class="nav_item" :class="$route.path == '/shop/staff' ? 'active' : ''" to="/shop/staff">员工管理</router-link>
      <router-link v-if="shopInfo.houtai != 0" class="nav_item" :class="$route.path == '/shop/freight' ? 'active' : ''" to="/shop/freight">运费设置</router-link>
    </div>

    <div class="right-menu">
      <el-dropdown class="avatar-container" trigger="click">
        <div class="avatar-wrapper">
          <div class="left">
            <img :src="avatar" class="user-avatar">
            <span>{{ shopInfo.name }}</span>
          </div>
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown" class="user-dropdown">
          <router-link v-if="shopInfo.houtai != 0" to="/shop">
            <el-dropdown-item>
              店铺后台
            </el-dropdown-item>
          </router-link>
          <router-link to="/shop/setaccount">
            <el-dropdown-item>
              账号设置
            </el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span style="display:block;">退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  components: { },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'shopInfo'
    ])
  },
  created() {

  },
  methods: {
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);

  .breadcrumb-container {
    float: left;
		height: 100%;
		display: flex;
		.nav_item{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 120px;
			cursor: pointer;
			color: #999;
			font-weight: 600;
		}
		.active{
			color: #fff;
			background-color: #4C85FF;
		}
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;
				.left{
					display: flex;
				}
        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
